<template>
    <!-- 前台的评论路由组件 -->
    <div class="big-container"> 
        <!-- 回到顶部 -->
        <el-backtop :bottom="100" :visibility-height="700">
            <div
            style="{
                height: 100%;
                width: 100%;
                background-color: #f2f5f6;
                box-shadow: 0 0 6px rgba(0,0,0, .12);
                text-align: center;
                line-height: 40px;
                color: #1989fa;
            }"
            >
            UP
            </div>
        </el-backtop>
        <el-backtop :visibility-height="700"></el-backtop>
        <!-- 返回主页 -->
        <div class="first-home" @click="returnFirstHome">主页</div>   
        <!-- 评论组件具体使用 -->
        <div class="container">
            <div class="title">
                评论
            </div>
            <div style="display: flex;justify-content: space-between;">
                <div class="ps">
                    文明上网理性发言!
                </div>
                <div style="line-height: 44px;color: #409EFF;">
                    {{dataList.length}} 条评论
                </div>
            </div>
            <!-- 头像与发送框 -->
            <div style="display: flex;justify-content: space-between;margin-top: 40px;">
                <el-avatar style="margin-top: 15px;margin-right: 30px;width: 75px;" :size="70"  :src="data.photo_url"></el-avatar>
                <div class="box-content box-logout"> 
                    <div class="box-textarea-block"> 
                        <textarea v-model="text" class="box-textarea" placeholder="说两句吧..."></textarea> 
                    </div> 
                    <span class="box-loginBtn" @click="faSong">发送</span>
                </div>
            </div>
            <!-- 评论 -->
            <div style="display: flex;justify-content: space-between;align-items: end;margin-top: 30px;">
                <div style="font-size: 20px;">全部评论</div>
            </div>
            <el-divider></el-divider>
            <!-- 具体的每条评论 -->
            <div v-for="item in dataList" :key="item.id">
                <div class="comment">
                    <!-- 头像 -->
                    <div>
                        <el-avatar :size="70" :src="item.comment_photo"></el-avatar>
                    </div>
                    <!-- 内容 -->
                    <div class="comment-context" style="margin-left: 25px;">
                        <div class="comment-context-one">
                            <div style="color: #409EFF;margin-right: 20px;">{{item.comment_name}}</div>
                            <div style="color: #999999;margin-right: 20px;">{{item.comment_time}}</div>
                            <div style="color: #409EFF;margin-right: 20px;">{{item.status}}</div>
                        </div>
                        <div class="comment-context-two">
                            {{ item.context }}
                        </div>

                    </div>
                </div>
                <el-divider></el-divider>
            </div>
        </div>
    </div>
</template>

<script>
    import myAxios from '@/tools/myAxios';
    export default {
        name:'UserComment',
        props:['item'],
        data() {
            return {
                // 所有评论数据
                dataList:[],
                // 当前登录用户的信息
                data:{},
                // 评论内容
                text:''
            }
        },
        methods:{
            // 返回前台首页
            returnFirstHome(){
                this.$router.push({path:'/index'})
            },
            // 评论
            faSong(){
                if(this.text.trim() === ''){
                    this.$message({
                            message: '评论不能为空!',
                            type: 'warning'
                    });
                    return;
                }

                myAxios(
                    'http://localhost:8088/admin/addcomment?active_id='+this.item.id+'&context='+this.text,
                    'get',
                    null,
                    (data)=>{
                        // 1. 提示评论成功
                        this.$message({
                            message: '评论成功!',
                            type: 'success'
                        });
                        // 2. 当前活动的所有评论信息
                        myAxios(
                            'http://localhost:8088/older/getallcommentbyactiveid?id='+this.item.id,
                            'get',
                            null,
                            (data)=>{
                                if(data.length !== 0){
                                    this.dataList = data;
                                }else{
                                    this.$message({
                                        message: '该活动没有评论信息!',
                                        type: 'warning'
                                    });
                                }
                            }
                        );
                    }
                )
            }
        },
        mounted(){
            // 1. 获取当前登录用户的信息
            this.data = JSON.parse(sessionStorage.getItem('user'));
            // 2. 当前活动的所有评论信息
            myAxios(
                'http://localhost:8088/older/getallcommentbyactiveid?id='+this.item.id,
                'get',
                null,
                (data)=>{
                    if(data.length !== 0){
                        this.dataList = data;
                    }else{
                        this.$message({
                            message: '该活动没有评论信息!',
                            type: 'warning'
                        });
                    }
                }
            );

        }
    }
</script>

<style lang="less" scoped>
.big-container{
    background-color: rgb(225, 230, 233);
    .first-home{
        height: 40px;
        width: 40px;
        position: fixed; 
        left: 95.3%; 
        top: 77%; 
        background-color: rgb(242, 245, 246);
        box-shadow: rgb(0 0 0 / 12%) 0px 0px 6px;
        text-align: center;
        line-height: 40px;
        color: rgb(25, 137, 250);
        font-weight: 600;
    }
    .first-home:hover{
        cursor: pointer;
        background-color:#dad8d8;
    }
    .container{
        height: 96vh;
        width: 60%;
        margin: 0 auto;
        background-color: #fff;
        border-radius: 10px;
        padding: 20px;
        overflow: auto;
        .title{
            font-size: 40px;
        }
        .ps{
            font-size: 14px;
            color: #cccccc;
            font-family: 'Microsoft Yahei','Helvetica','sans-serif';
            line-height: 44px;
        }

        .box-logout,.box-content {
            height: 84px;
            padding-bottom: 10px;
            width: 98.6%;
        }
        .box-content {
            border: 3px solid #f0f0f0;
            position: relative;
            .box-loginBtn {
                position: absolute;
                right: -3px;
                top: -3px;
                z-index: 1;
                width: 100px;
                height: 100px;
                background-color: #379be9;
                font-size: 16px;
                line-height: 100px;
                text-align: center;
                color: #fff;
                cursor: pointer;
            }
        }
        .box-logout{
            .box-textarea-block {
                margin-right: 110px;
                height: 72px;
                margin-left: 12px;
                margin-top: 12px;
                margin-bottom: 12px;

                textarea {
                    outline: none;
                    resize: none;
                    overflow: auto;
                }
                .box-textarea {
                    height: 100%;
                    width: 100%;
                    display: block;
                    border: none;
                    font-size: 14px;
                    line-height: 24px;
                    color: #4b4b4b;
                }
            }

        } 

        .comment{
            display: flex;
            .comment-context{ 
                margin-left: 25px;
                .comment-context-one{
                    display: flex;
                    margin-top: 10px;
                    font-family: 'Microsoft Yahei','Helvetica','sans-serif'; ;
                }
                .comment-context-two{
                    font-size: 14px;
                    color: #4b4b4b;
                    line-height: 24px;
                    margin-top: 10px;
                    margin-right: 7px;
                }
                .comment-context-three{
                    width: 96%;
                    background-color: #f7f4f4;
                    margin-top: 15px;
                    padding: 15px;
                    color: #606060;
                    line-height: 34px;

                    .appear-answer{
                        color: #ADADAD;
                        font-size: 15px;
                        font-family: 'Microsoft Yahei','Helvetica','sans-serif';
                    }

                    /deep/ .appear-answer:hover{
                        cursor: pointer;
                        color: #409EFF;
                    }
                }
                .comment-context-four{
                    color: #adadad;
                    font-size: 14px;
                    margin-top: 15px;
                    margin-bottom: 10px;
                }
                .comment-context-four:hover{
                    cursor: pointer;
                    color: #409EFF;
                }
            }
        }

    }
}
</style>